package com.zxn.rv;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @author: njb
 * @date: 2020/2/23 0023 17:12
 * @desc: 输入公里数
 */
public class InPutNumberActivity extends AppCompatActivity {
    private EditText etNumber;
    private String etKm ;
    private TextView tvBack;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inputnumber);
        initView();
    }

    private void initView() {
        etNumber = findViewById(R.id.et_number);
        tvBack = findViewById(R.id.tv_back);
        etNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                etKm = etNumber.getText().toString();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(TextUtils.isEmpty(etNumber.getText().toString())){
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra("data",etKm);
                setResult(RESULT_OK,intent);
                Log.d("-----return km-----", etKm);
                finish();
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();

    }
}
